import { LoginActions } from '../actions'
import { User } from '../Types'
import { LOGIN, LOGOUT } from '../Constants'
import Cache from '../../utils/cache'
// 初始化
const initState= {
  id: '',
  photo: '',
  userName: '',
  tureName: '',
  role: '',
  token: '',
  venderInfo: {},
  loading: false
}
export function userReducer(state: User = initState, action: LoginActions): User {
  switch (action.type) {
    case LOGIN:
      Cache.sessionPut('LOGIN_USER', action.payload)
      return action.payload
    case LOGOUT:
      Cache.sessionRemove('LOGIN_USER')
      return initState
  }
  return state
}